#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

int numMoves;

void printBoard(vector<vector<int> > &board)
{
    for (int i = 0; i < board.size(); i++) {
	for (int j = 0; j < board[0].size(); j++)
	    cout << board[i][j] << " ";
	cout << endl;
    }
}

int makeMove(vector<vector<int> > &board, int x, int y, int move)
{
    if (board[x][y] != 0) return -1;
    board[x][y] = move;
    numMoves++;

    //printBoard(board);
    //getchar();

    for (int i = 0; i < 3; i++) {
	if (board[x][i] != move) {
	    break;
	}
	if (i == 2) return move;
    }

    for (int i = 0; i < 3; i++) {
	if (board[i][y] != move) {
	    break;
	}
	if (i == 2) return move;
    }

    if (x == y) {
	for (int i = 0; i < 3; i++) {
	    if (board[i][i] != move) break;
	    if (i == 2) return move;
	}
    }

    for (int i = 0; i < 3; i++) {
        if (board[i][3-1-i] != move) break;
        if (i == 2) return move;
    }  

    if (numMoves == 9) return 9;
    return 0;
}

int main(int argc, char **argv)
{
    for (int i = 0; i < 10; i++) {
	vector<vector<int> > board(3, vector<int>(3, 0)); 
	int move = 1;
        numMoves = 0;
        int result = 0;
	while (1) {
	    int x = rand()%3;
	    int y = rand()%3;
	    result = makeMove(board, x, y, move);
	    if (result == -1) continue;
	    if (result == move || result == 9) break;
	    move = (move == 1) ? 2 : 1;
	}
	printBoard(board);
	if (result == 9) cout << "Game Draw" << endl;
	else cout << result << "win the game" << endl;
	getchar();
    }
}
